package com.song.JavaThread_day02.ch2_5;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class PrintQueue {
	
	
	private final Lock queueLock = new ReentrantLock();
	
	public  void printJob(Object  document)
	{
		queueLock.lock();
		
		Long duration = (long)(Math.random()*10000);
		
		System.out.println(Thread.currentThread().getName()+" print queue :print a job "+(duration/1000)+"seconds");
		
		try {
			Thread.sleep(duration);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			queueLock.unlock();
		}
		
	}
}
